home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / eslide.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  21.9 KB  |  694 lines

  1. // $Id: eslide.cc 1.5 1998/01/13 19:56:31 dlorre Exp $
  2. #include <graphics/gfxmacros.h>
  3. #include <intuition/classes.h>
  4. #include <intuition/classusr.h>
  5. #include <intuition/gadgetclass.h>
  6. #include <intuition/cghooks.h>
  7. #include <intuition/icclass.h>
  8. #include <utility/tagitem.h>
  9. #include <utility/hooks.h>
  10. #include <libraries/gadtools.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <mydebug.h>
  14. #include <compiler.h>
  15.  
  16. #include "gadgets/eslide.h"
  17. #include "gadgetlist.h"
  18. #include "window.h"
  19. #include "screen.h"
  20. #include "gadgets/eclass.h"
  21.  
  22. #include <proto/graphics.h>
  23. #include <proto/intuition.h>
  24. #include <proto/utility.h>
  25. #include <clib/alib_protos.h>
  26.  
  27. static Class *BOOPSIeslide ;
  28. static int InitESlide(void) ;
  29. static void FreeESlide(void) ;
  30.  
  31. extern "C" STDARGS ULONG HookEntry() ;
  32.  
  33. // ========================================================================
  34. // ============================  ESLIDE CLASS =============================
  35. // ========================================================================
  36.  
  37.  
  38. eslide::eslide(gadgetlist *gl,
  39.                void (window::*func)(gadget *, unsigned long, unsigned short),
  40.                long min,
  41.                long max,
  42.                long level,
  43.                long freedom,
  44.                const char *t,
  45.                long flags) : gadget(gl, func)
  46. {
  47. int i, l1, l2 ;
  48. BOOL underset = FALSE ;
  49. UWORD *pens = gl->win->ws->drawinfo->dri_Pens;
  50.  
  51.     smin = min ;
  52.     smax = max ;
  53.     cursel = level ;
  54.     disabled = FALSE ;
  55.  
  56.     InitESlide() ;
  57.  
  58.     if (t) {
  59.  
  60.         it1 = new IntuiText ;
  61.         it2 = new IntuiText ;
  62.         it3 = new IntuiText ;
  63.  
  64.         plain = new TTextAttr ;
  65.         underline = new TTextAttr ;
  66.  
  67.         it1->FrontPen = it2->FrontPen = it3->FrontPen =
  68.             pens[(flags&NG_HIGHLABEL)?HIGHLIGHTTEXTPEN:TEXTPEN] ;
  69.         it1->BackPen = it2->BackPen = it3->BackPen = 0 ;
  70.         it1->DrawMode = it2->DrawMode = it3->DrawMode = JAM1 ;
  71.  
  72.         norm1 = new char[strlen(t)+1] ;
  73.         norm2 = new char[strlen(t)+1] ;
  74.         under = new char[2] ;
  75.  
  76.         underkey(t) ;
  77.  
  78.         CopyMem(gl->win->ws->scr->Font, plain, sizeof(struct TTextAttr)) ;
  79.         CopyMem(gl->win->ws->scr->Font, underline, sizeof(struct TTextAttr)) ;
  80.         underline->tta_Style |= FSF_UNDERLINED ;
  81.         font = OpenFont((TextAttr *)underline) ;
  82.  
  83.         for (i=l1=l2=0; t[i]; i++) {
  84.             if (t[i] == '_') {
  85.                 if (t[i+1]) under[0] = t[++i] ;
  86.                 underset = TRUE ;
  87.             }
  88.             else {
  89.                 if (underset) {
  90.                     norm2[l2++] = t[i] ;
  91.                 }
  92.                 else {
  93.                     norm1[l1++] = t[i] ;
  94.                 }
  95.             }
  96.         }
  97.         norm1[l1] = '\0' ;
  98.         norm2[l2] = '\0' ;
  99.         under[1] = '\0' ;
  100.  
  101.         if (l1) {
  102.             it1->IText = (UBYTE *)norm1 ;
  103.             it1->ITextFont = (TextAttr *)plain ;
  104.             if (underset) {
  105.                 it1->NextText = it2 ;
  106.                 it2->LeftEdge = short(IntuiTextLength(it1)) ;
  107.                 it2->IText = (UBYTE *)under ;
  108.                 it2->ITextFont = (TextAttr *)underline ;
  109.                 if (l2) {
  110.                     it2->NextText = it3 ;
  111.                     it3->LeftEdge = short(it2->LeftEdge + IntuiTextLength(it2)) ;
  112.                     it3->IText = (UBYTE *)norm2 ;
  113.                     it3->ITextFont = (TextAttr *)plain ;
  114.                 }
  115.             }
  116.         }
  117.         else if (underset) {
  118.             it1->IText = (UBYTE *)under ;
  119.             it1->ITextFont = (TextAttr *)underline ;
  120.             it1->NextText = it2 ;
  121.             it2->LeftEdge = short(IntuiTextLength(it1)) ;
  122.             it2->IText = (UBYTE *)norm2 ;
  123.             it2->ITextFont = (TextAttr *)plain ;
  124.         }
  125.     }
  126.     gad = gl->gad  = (Gadget *)NewObject(BOOPSIeslide, NULL,
  127.             GA_ID,              gl->ng->ng_GadgetID,
  128.             GA_Top,             gl->ng->ng_TopEdge,
  129.             GA_Left,            gl->ng->ng_LeftEdge,
  130.             GA_Width,           gl->ng->ng_Width,
  131.             GA_Height,          gl->ng->ng_Height,
  132.  
  133.             GA_Immediate,       TRUE,
  134.             GA_Previous,        gl->gad,
  135.             GA_RelVerify,       TRUE,
  136.  
  137.             GA_UserData,        EGA_Level,
  138.             PGA_Freedom,        freedom,
  139.             GA_IntuiText,       it1 ,
  140.  
  141.             EGA_Min,            min,
  142.             EGA_Max,            max,
  143.             EGA_Flags,          flags,
  144.             EGA_Level,          level,
  145.             EGA_TextAttr,       gl->ng->ng_TextAttr,
  146.             EGA_XPens,          gl->win->ws->xpens,
  147.             EGA_GPen,           gl->gpen,
  148.  
  149.             TAG_DONE);
  150.  
  151. }
  152.  
  153. eslide::~eslide()
  154. {
  155.     if (norm1) delete norm1 ;
  156.     if (norm2) delete norm2 ;
  157.     if (under) delete under ;
  158.  
  159.     if (it1) delete it1 ;
  160.     if (it2) delete it2 ;
  161.     if (it3) delete it3 ;
  162.  
  163.     if (plain) delete plain ;
  164.     if (underline) delete underline ;
  165.  
  166.     if (gad) DisposeObject(gad) ;
  167.     if (font) CloseFont(font) ;
  168.     FreeESlide() ;
  169. }
  170.  
  171. void eslide::set(long level, long min, long max, short disable)
  172. {
  173.     if (((level == -1) || (cursel == level)) && ((min == -1) || (smin == min))
  174.         && ((max == -1) ||(max == smax)) && (disable == disabled)) {
  175.         // nothing to do
  176.         return ;
  177.     }
  178.  
  179.     if (min != -1) smin = min ;
  180.     if (max != -1) smax = max ;
  181.     if (cursel != -1) cursel = level ;
  182.     disabled = disable ;
  183.  
  184.     SetGadgetAttrs(gad, w, NULL,
  185.         (level != -1)?EGA_Level:TAG_IGNORE,  level,
  186.         (min != -1)?EGA_Min:TAG_IGNORE,      min,
  187.         (max != -1)?EGA_Max:TAG_IGNORE,      max,
  188.         GA_Disabled,                        disable,
  189.         TAG_END) ;
  190. }
  191.  
  192. void eslide::action(unsigned long classe, unsigned short code)
  193. {
  194.     if (classe != IDCMP_GADGETDOWN) {
  195.         cursel = code ;
  196.         gadget::action(classe, code) ;
  197.     }
  198. }
  199.  
  200. void eslide::keystroke(BOOL shifted)
  201. {
  202.     if (shifted) {
  203.         cursel-- ;
  204.         if (cursel < smin) cursel= smax ;
  205.     }
  206.     else {
  207.         cursel++ ;
  208.         if (cursel > smax)
  209.             cursel = smin ;
  210.     }
  211.     SetGadgetAttrs(gad, w, NULL,
  212.         EGA_Level,  cursel,
  213.         TAG_END) ;
  214.     gadget::action(NULL, cursel) ;
  215. }
  216.  
  217.  
  218.  
  219. // ========================================================================
  220. // =============================== ESLIDE =================================
  221. // ========================================================================
  222.  
  223. struct SlideINST {
  224.     long        Min ;       // limits and level values
  225.     long        Max ;
  226.     long        Level ;
  227.     long        Total ;
  228.  
  229.     long        Top ;
  230.     long        DTop ;
  231.     long        PTop ;      // Previous Top
  232.  
  233.     long        GLeft ;     // Gadget coordinates
  234.     long        GTop ;
  235.     long        GWidth ;
  236.     long        GHeight ;
  237.  
  238.     long        KLeft ;     // Knob coordinates
  239.     long        KTop ;
  240.     long        KWidth ;
  241.     long        KHeight ;
  242.     long        KRight ;
  243.     long        KBottom ;
  244.  
  245.     long        Orient ;     // indicates the orientation (HORIZ or VERT)
  246.     long        Flags ;     // the NewGadget Flags
  247.  
  248.     BOOL        KnobHit ;   // User is moving the Knob
  249.     BOOL        RedrawAll ; // Complete Refresh
  250.     BOOL        Disabled ;  // for redraw check
  251.     BOOL        Direction ;
  252.  
  253.     TextAttr    *TAttr ;  // How to display the level value
  254.     TextFont    *Font ;
  255.     IntuiText   *IText ;
  256.  
  257.     UWORD       *XPens ;    // rendering information
  258.     UWORD       GPen ;
  259. } ;
  260.  
  261. static ULONG STDARGS dispatchESlide(Class *cl, Object *o, Msg msg);
  262.  
  263. static void    NotifySlide(Class *, Object *, ULONG, long, gpInput *) ;
  264.  
  265. static ULONG   RenderESlide(Class *, Gadget *, gpRender *) ;
  266.  
  267. static void    SlideLims(SlideINST *inst, Gadget *g, GadgetInfo *gi) ;
  268.  
  269.  
  270.  
  271. static unsigned short ditherData[2] = {0x5555,0xAAAA};
  272. static int ESlideCnt = 0 ;
  273. int InitESlide(void)
  274. {
  275.     if (ESlideCnt) {
  276.         ESlideCnt++ ;
  277.     }
  278.     else if (!(BOOPSIeslide = MakeClass(NULL, (UBYTE *)"gadgetclass", NULL,
  279.         sizeof(SlideINST), 0))) {
  280.         ESlideCnt = 0 ;
  281.     }
  282.     else {
  283.         BOOPSIeslide->cl_Dispatcher.h_Entry = (HOOKFUNC)HookEntry ;
  284.         BOOPSIeslide->cl_Dispatcher.h_SubEntry = (HOOKFUNC)dispatchESlide;
  285.         BOOPSIeslide->cl_Dispatcher.h_Data = NULL ;
  286.         ESlideCnt = 1 ;
  287.     }
  288.     return ESlideCnt ;
  289. }
  290.  
  291. void FreeESlide(void)
  292. {
  293.     ESlideCnt-- ;
  294.     if (!ESlideCnt)
  295.         FreeClass(BOOPSIeslide) ;
  296. }
  297.  
  298. ULONG SAVEDS STDARGS dispatchESlide(Class *cl, Object *o, Msg msg)
  299. {
  300. SlideINST *inst ;
  301. ULONG retval = FALSE ;
  302. Object *object ;
  303.  
  304.     GETA4 ;
  305.     if (msg->MethodID != OM_NEW)
  306.         inst = (SlideINST *)INST_DATA(cl, o) ;
  307.     switch (msg->MethodID) {
  308.     case OM_NEW:
  309.         if (object = (Object *)DoSuperMethodA(cl, o, msg)) {
  310.             inst = (SlideINST *)INST_DATA(cl, object) ;
  311.             inst->KnobHit = FALSE ;
  312.             inst->Min = (long)GetTagData(EGA_Min, 0, ((opSet *)msg)->ops_AttrList) ;
  313.             inst->Max = (long)GetTagData(EGA_Max, 15, ((opSet *)msg)->ops_AttrList) ;
  314.             inst->Level = (long)GetTagData(EGA_Level, 0, ((opSet *)msg)->ops_AttrList) ;
  315.             inst->Total = inst->Max - inst->Min + 1 ;
  316.             inst->TAttr = (TextAttr *)GetTagData(EGA_TextAttr, 0, ((opSet *)msg)->ops_AttrList) ;
  317.             inst->XPens = (UWORD *)GetTagData(EGA_XPens, NULL, ((opSet *)msg)->ops_AttrList) ;
  318.             inst->GPen = (UWORD)GetTagData(EGA_GPen, NULL, ((opSet *)msg)->ops_AttrList) ;
  319.             inst->Orient = (long)GetTagData(PGA_Freedom, LORIENT_HORIZ, ((opSet *)msg)->ops_AttrList) ;
  320.             inst->IText = (IntuiText *)GetTagData(GA_IntuiText,
  321.                 NULL,
  322.                 ((opSet *)msg)->ops_AttrList) ;
  323.             inst->Flags = (LONG)GetTagData(EGA_Flags, PLACETEXT_LEFT,
  324.                     ((opSet *)msg)->ops_AttrList) ;
  325.  
  326.             if (inst->TAttr)
  327.                 inst->Font = OpenFont(inst->TAttr) ;
  328.             else
  329.                 inst->Font = NULL ;
  330.             inst->Top = inst->Level - inst->Min ;
  331.             inst->RedrawAll = TRUE ;
  332.             retval = (ULONG)object ;
  333.         }
  334.         break ;
  335.     case OM_DISPOSE:
  336.         CloseFont(inst->Font) ;
  337.         retval = DoSuperMethodA(cl, o, msg) ;
  338.         break ;
  339.     case GM_GOACTIVE:
  340.         {
  341.         gpInput *gpi = (gpInput *)msg ;
  342.             if (gpi->gpi_IEvent) {
  343.                 ((Gadget *)o)->Flags |= GFLG_SELECTED ;
  344.                 inst->RedrawAll = FALSE ;
  345.  
  346.                 // is the mouse inside the knob ?
  347.                 if (((gpi->gpi_Mouse.X + inst->GLeft) >= inst->KLeft) &&
  348.                     ((gpi->gpi_Mouse.X + inst->GLeft) <= inst->KRight) &&
  349.                     ((gpi->gpi_Mouse.Y + inst->GTop) >= inst->KTop) &&
  350.                     ((gpi->gpi_Mouse.Y + inst->GTop) <= inst->KBottom)) {
  351.                         inst->KnobHit = TRUE ;
  352.                         inst->Direction = TRUE ;
  353.                         if (inst->Orient & LORIENT_HORIZ)
  354.                             inst->DTop = (gpi->gpi_Mouse.X * inst->Total) / inst->GWidth - inst->Top ;
  355.                         else
  356.                             inst->DTop = ( inst->Total - (gpi->gpi_Mouse.Y * inst->Total) / inst->GHeight) - inst->Top ;
  357.                 }
  358.                 else {
  359.                     inst->Direction = FALSE ;
  360.                     if (inst->Orient & LORIENT_HORIZ) {
  361.                         if ((gpi->gpi_Mouse.X + inst->GLeft)<= inst->KLeft)
  362.                             inst->Top-- ;
  363.                         else
  364.                             inst->Top++ ;
  365.                     }
  366.                     else {
  367.                         if ((gpi->gpi_Mouse.Y + inst->GTop)<= inst->KTop)
  368.                             inst->Top++ ;
  369.                         else
  370.                             inst->Top-- ;
  371.                     }
  372.                 }
  373.                 retval = GMR_MEACTIVE ;
  374.                 RenderESlide(cl, (Gadget *)o, (gpRender *)msg) ;
  375.                 NotifySlide(cl, o, OPUF_INTERIM, inst->Level, gpi) ;
  376.                 *(gpi->gpi_Termination) = inst->Level ;
  377.         }
  378.         else
  379.             retval = GMR_NOREUSE ;
  380.         }
  381.         break ;
  382.     case GM_RENDER:
  383.         inst->RedrawAll = BOOL(((gpRender *)msg)->gpr_Redraw == GREDRAW_REDRAW) ;
  384.         retval = RenderESlide(cl, (Gadget *)o, (gpRender *)msg) ;
  385.         break ;
  386.     case GM_HANDLEINPUT:
  387.         {
  388.             gpInput *gpi = (gpInput *)msg ;
  389.             InputEvent *ie = gpi->gpi_IEvent ;
  390.  
  391.             inst->PTop = inst->Top ;
  392.             retval = GMR_MEACTIVE ;
  393.  
  394.             if (ie->ie_Class == IECLASS_RAWMOUSE) {
  395.                 switch (ie->ie_Code) {
  396.                     case SELECTUP:
  397.                         if (((gpi->gpi_Mouse).X < inst->GLeft) ||
  398.                            ((gpi->gpi_Mouse).X > inst->GLeft + inst->GWidth) ||
  399.                            ((gpi->gpi_Mouse).Y < inst->GTop) ||
  400.                            ((gpi->gpi_Mouse).Y > inst->GTop + inst->GHeight) ) {
  401.                                 *(gpi->gpi_Termination) = inst->Level ;
  402.                                 retval = GMR_NOREUSE | GMR_VERIFY ;
  403.                         }
  404.                         else
  405.                             retval = GMR_NOREUSE ;
  406.                         break ;
  407.                     case MENUDOWN:
  408.                         retval = GMR_REUSE ;
  409.                         NotifySlide(cl, o, 0, inst->Level, (gpInput *)msg) ;
  410.                         break ;
  411.                     default:
  412.                         retval = GMR_MEACTIVE ;
  413.                 }
  414.             }
  415.             else if (ie->ie_Class == IECLASS_TIMER && inst->Direction) {
  416.                 if (inst->Orient & LORIENT_HORIZ)
  417.                     inst->Top = ((gpi->gpi_Mouse.X) * inst->Total) /
  418.                         inst->GWidth - inst->DTop ;
  419.                 else
  420.                     inst->Top = (inst->Total-((gpi->gpi_Mouse.Y) * inst->Total) /
  421.                         inst->GHeight) - inst->DTop ;
  422.  
  423.                 if (inst->PTop != inst->Top) {
  424.                     inst->RedrawAll = FALSE ;
  425.                     RenderESlide(cl, (Gadget *)o, (gpRender *)msg) ;
  426.                     NotifySlide(cl, o, OPUF_INTERIM, inst->Level, gpi) ;
  427.                 }
  428.             }
  429.         }
  430.         break ;
  431.     case GM_GOINACTIVE:
  432.         ((Gadget *)o)-> Flags &= ~GFLG_SELECTED ;
  433.         inst->KnobHit = FALSE ;
  434.         inst->RedrawAll = FALSE ;
  435.         RenderESlide(cl, (Gadget *)o, (gpRender *)msg) ;
  436.         break ;
  437.     case OM_GET:
  438.         switch (((opGet *)msg)->opg_AttrID) {
  439.         case EGA_Min:
  440.             retval = inst->Min ;
  441.             break ;
  442.         case EGA_Max:
  443.             retval = inst->Max ;
  444.             break ;
  445.         case EGA_Level:
  446.             retval = inst->Level ;
  447.             break ;
  448.         default:
  449.             retval = DoSuperMethodA(cl, o, msg) ;
  450.         }
  451.         break ;
  452.     case OM_SET:
  453.         retval = DoSuperMethodA(cl, o, msg) ;
  454.         if ( FindTagItem(EGA_Min, ((opSet *)msg)->ops_AttrList) ||
  455.             FindTagItem(EGA_Max, ((opSet *)msg)->ops_AttrList) ||
  456.             FindTagItem(EGA_Level, ((opSet *)msg)->ops_AttrList) ) {
  457.             RastPort *rp ;
  458.             Gadget *g  = (Gadget *)o ;
  459.             LONG    redraw ;
  460.  
  461.             inst->Min = (long)GetTagData(EGA_Min, inst->Min, ((opSet *)msg)->ops_AttrList) ;
  462.             inst->Max = (long)GetTagData(EGA_Max, inst->Max, ((opSet *)msg)->ops_AttrList) ;
  463.             inst->Level = (long)GetTagData(EGA_Level, inst->Level, ((opSet *)msg)->ops_AttrList) ;
  464.             inst->Total = inst->Max - inst->Min + 1 ;
  465.             inst->Top = inst->Level - inst->Min ;
  466.             redraw = (inst->Disabled ^ (g->Flags & GFLG_DISABLED)) ? GREDRAW_REDRAW : GREDRAW_UPDATE ;
  467.             inst->Disabled = g->Flags & GFLG_DISABLED ;
  468.  
  469.             if (rp = ObtainGIRPort( ((opSet *)msg)->ops_GInfo) ) {
  470.                 DoMethod(o, GM_RENDER, ((opSet *)msg)->ops_GInfo, rp, redraw) ;
  471.                 ReleaseGIRPort(rp) ;
  472.             }
  473.         }
  474.         break ;
  475.     default :
  476.         retval = DoSuperMethodA(cl, o, msg) ;
  477.         break ;
  478.     }
  479.     return retval ;
  480. }
  481.  
  482.  
  483. void SAVEDS NotifySlide(Class *cl, Object *o, ULONG flags, long level, gpInput *gpi)
  484. {
  485. static TagItem tt[3] ;
  486.  
  487.     GETA4 ;
  488.     tt[0].ti_Tag = EGA_Level ;
  489.     tt[0].ti_Data = level  ;
  490.  
  491.     tt[1].ti_Tag = GA_ID ;
  492.     tt[1].ti_Data = ((Gadget *)o)->GadgetID ;
  493.  
  494.     tt[2].ti_Tag = TAG_DONE ;
  495.  
  496.     DoSuperMethod(cl, o, OM_NOTIFY, tt, gpi->gpi_GInfo, flags) ;
  497. }
  498.  
  499. ULONG SAVEDS RenderESlide(Class *cl, Gadget *g, gpRender *msg)
  500. {
  501. RastPort    *rp ;
  502. ULONG       retval = TRUE ;
  503. UWORD       *pens = msg->gpr_GInfo->gi_DrInfo->dri_Pens ;
  504. SlideINST   *inst = (SlideINST *)INST_DATA(cl, (Object *)g) ;
  505. char        kbuf[8] ;
  506. WORD        ls ;
  507. LONG        l, t, len ; // left, top, len utilisés pour l'affichage
  508. IntuiText   *itext ;    // affichage du label
  509.  
  510.     GETA4 ;
  511.     if (msg->MethodID == GM_RENDER)
  512.         rp = msg->gpr_RPort ;
  513.     else
  514.         rp = ObtainGIRPort(msg->gpr_GInfo) ;
  515.     if (rp) {
  516.         SetAPen(rp, pens[SHADOWPEN]) ;
  517.         SetDrMd(rp, JAM1) ;
  518.         SetFont(rp, inst->Font) ;
  519.  
  520.         WaitTOF() ;
  521.         if (g->Flags & GFLG_DISABLED) {
  522.             SlideLims(inst, g, msg->gpr_GInfo) ;
  523.             SetAPen(rp, pens[BACKGROUNDPEN]) ;
  524.             RectFill(rp,
  525.                 inst->GLeft,
  526.                 inst->GTop,
  527.                 inst->GLeft+inst->GWidth,
  528.                 inst->GTop+inst->GHeight) ;
  529.             goto out ;
  530.         }
  531.         else if (inst->RedrawAll) {
  532.             SlideLims(inst, g, msg->gpr_GInfo) ;
  533.             SetAPen(rp, inst->XPens[GFILL_PEN]) ;
  534.             RectFill(rp,
  535.                 inst->GLeft,
  536.                 inst->GTop,
  537.                 inst->GLeft+inst->GWidth-1,
  538.                 inst->GTop+inst->GHeight-1) ;
  539.  
  540.             SetAPen(rp, pens[SHINEPEN]) ;
  541.  
  542.             Move(rp, inst->GLeft+1, inst->GTop+inst->GHeight-1) ;
  543.             Draw(rp, inst->GLeft+1, inst->GTop+1) ;
  544.             Draw(rp, inst->GLeft+inst->GWidth-1, inst->GTop+1) ;
  545.             Draw(rp, inst->GLeft+inst->GWidth-1, inst->GTop+inst->GHeight-1) ;
  546.             Draw(rp, inst->GLeft+1, inst->GTop+inst->GHeight-1) ;
  547.  
  548.             SetAPen(rp, pens[SHADOWPEN]) ;
  549.  
  550.             Move(rp, inst->GLeft, inst->GTop) ;
  551.             Draw(rp, inst->GLeft+inst->GWidth-2, inst->GTop) ;
  552.             Draw(rp, inst->GLeft+inst->GWidth-2, inst->GTop+inst->GHeight-2) ;
  553.             Draw(rp, inst->GLeft, inst->GTop+inst->GHeight-2) ;
  554.             Draw(rp, inst->GLeft, inst->GTop) ;
  555.             if (inst->IText) {  // Le gadget possède un label
  556.                 itext = inst->IText ;
  557.  
  558.                 // recherche du dernier itext pour la longueur
  559.  
  560.                 while (itext->NextText) itext = itext->NextText ;
  561.  
  562.                 // Le calcul par défaut est pour PLACETEXT_IN
  563.  
  564.                 len = IntuiTextLength(itext) + itext->LeftEdge ;
  565.                 t = inst->GTop + 1 +
  566.                     (inst->GHeight - itext->ITextFont->ta_YSize -2) / 2 ;
  567.                 l = inst->GLeft + 1 + (inst->GWidth - len - 2) / 2 ;
  568.  
  569.  
  570.                 if (inst->Flags & PLACETEXT_RIGHT) {
  571.                     l = inst->GLeft + inst->GWidth + 4 ;
  572.                 }
  573.                 else if (inst->Flags & PLACETEXT_ABOVE) {
  574.                     t = inst->GTop - itext->ITextFont->ta_YSize - 4 ;
  575.                 }
  576.                 else if (inst->Flags & PLACETEXT_BELOW) {
  577.                     t = inst->GTop + inst->GHeight + 4 ;
  578.                 }
  579.                 else if (!(inst->Flags & PLACETEXT_IN)) {  // PLACETEXT_LEFT
  580.                     l = inst->GLeft - len - 4 ;
  581.                 }
  582.                 PrintIText(rp, inst->IText, l, t) ;
  583.             }
  584.         }
  585.         else {
  586.             SetAPen(rp, inst->XPens[GFILL_PEN]) ;
  587.             RectFill(rp,
  588.                 inst->KLeft,
  589.                 inst->KTop,
  590.                 inst->KRight,
  591.                 inst->KBottom) ;
  592.             SlideLims(inst, g, msg->gpr_GInfo) ;
  593.         }
  594.         SetAPen(rp, pens[FILLPEN]) ;
  595.  
  596.         SetAfPt(rp, ditherData, 1) ;
  597.         RectFill(rp, inst->KLeft,
  598.                      inst->KTop,
  599.                      inst->KRight,
  600.                      inst->KBottom ) ;
  601.  
  602.         SetAfPt(rp, NULL, 0 ) ; // Fin du tramage
  603.  
  604.         SetAPen(rp, pens[(g->Flags & GFLG_SELECTED)?SHADOWPEN:SHINEPEN]) ;
  605.  
  606.         Move(rp, inst->KLeft+1, inst->KBottom) ;
  607.         Draw(rp, inst->KLeft+1, inst->KTop+1) ;
  608.         Draw(rp, inst->KRight, inst->KTop+1) ;
  609.         Draw(rp, inst->KRight, inst->KBottom) ;
  610.         Draw(rp, inst->KLeft+1, inst->KBottom) ;
  611.  
  612.         SetAPen(rp, pens[(g->Flags & GFLG_SELECTED)?SHINEPEN:SHADOWPEN]) ;
  613.  
  614.         Move(rp, inst->KLeft, inst->KTop) ;
  615.         Draw(rp, inst->KRight-1, inst->KTop) ;
  616.         Draw(rp, inst->KRight-1, inst->KBottom-1) ;
  617.         Draw(rp, inst->KLeft, inst->KBottom-1) ;
  618.         Draw(rp, inst->KLeft, inst->KTop) ;
  619.  
  620.         SetAPen(rp, (g->Flags & GFLG_SELECTED) ? pens[HIGHLIGHTTEXTPEN] :
  621.                     inst->GPen) ;
  622.  
  623.  
  624.         sprintf(kbuf, "%ld", inst->Level) ;
  625.         ls = strlen(kbuf) ;
  626.         Move(   rp,
  627.                 inst->KLeft+(inst->KWidth - TextLength(rp, kbuf, ls))/2,
  628.                 inst->KTop+(inst->KHeight-rp->TxHeight)/2+rp->TxBaseline ) ;
  629.  
  630.         Text(rp, kbuf, ls) ;
  631.  
  632. out:
  633.         if (msg->MethodID != GM_RENDER)
  634.             ReleaseGIRPort(rp) ;
  635.  
  636.     }
  637.     else
  638.         retval = FALSE ;
  639.     return retval ;
  640. }
  641.  
  642.  
  643. void SAVEDS SlideLims(SlideINST *inst, Gadget *g, GadgetInfo *gi)
  644. {
  645.  
  646.     GETA4 ;
  647.     // we must not go outside the limits
  648.  
  649.     if (inst->Top < 0)
  650.         inst->Top = 0 ;
  651.     else if (inst->Top >= inst->Total)
  652.         inst->Top = inst->Total - 1 ;
  653.  
  654.     inst->Level = inst->Top + inst->Min ;
  655.  
  656.     inst->GLeft = g->LeftEdge ;
  657.     inst->GTop = g->TopEdge ;
  658.     inst->GWidth = g->Width  ;
  659.     inst->GHeight = g->Height ;
  660.  
  661.     if (inst->Orient & LORIENT_HORIZ) {
  662.         inst->KTop = inst->GTop + 2 ;
  663.         inst->KHeight = inst->GHeight - 4 ;
  664.  
  665.         inst->KWidth = 40 ;
  666.         if (inst->Total > 1) {
  667.             inst->KLeft = g->LeftEdge + 2 +
  668.             ((inst->GWidth-inst->KWidth-4) * inst->Top) / (inst->Total-1) ;
  669.         }
  670.         else
  671.             inst->KLeft = g->LeftEdge+2 ;
  672.  
  673.     }
  674.     else {
  675.         inst->KLeft = inst->GLeft + 2 ;
  676.         inst->KHeight = inst->TAttr->ta_YSize+4 ;
  677.  
  678.         if (inst->Total > 1) {
  679.             inst->KTop = g->TopEdge + 2 + ((inst->GHeight-inst->KHeight-4) *
  680.                 (inst->Total-inst->Top)) / (inst->Total-1) ;
  681.         }
  682.         else
  683.             inst->KTop = g->TopEdge + 2 ;
  684.  
  685.         inst->KWidth = inst->GWidth-4 ;
  686.  
  687.     }
  688.     inst->KRight = inst->KLeft + inst->KWidth - 1 ;
  689.     inst->KBottom = inst->KTop + inst->KHeight - 1 ;
  690.  
  691. }
  692.  
  693.  
  694.